package com.seataxa.order.service.impl;

import com.seataxa.order.mapper.OrderMapper;
import com.seataxa.order.remote.StockClient;
import com.seataxa.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/****************************************************
 *
 * @author lbf
 * @date 2025/7/16 13:35
 ****************************************************/
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private StockClient stockClient;
    @Autowired
    private OrderMapper orderMapper;

    @GlobalTransactional  //开启全局事务
    @Override
    public void create() {

        //扣库存
        stockClient.decrement();

        /**
         * 模拟异常，
         */
        int a = 1/0;

        //生成订单
        orderMapper.create();
    }
}
